package com.caishi.lkx.exam.model;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.zzw.common.entity.impl.BaseEntity;
import com.zzw.common.service.model.NameModel;
import com.zzw.common.service.model.base.SortModel;
import com.caishi.lkx.exam.ienum.type.ColumnType;
import com.caishi.lkx.order.IAssetsModel;
import com.caishi.lkx.order.ienum.status.AssetsStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

import java.time.LocalDateTime;
import java.util.List;

@Schema(title = "sku管理")
@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName(value = "ex_package_sku", autoResultMap = true)
public class PackageSkuModel extends BaseEntity<PackageSkuModel> implements NameModel<PackageSkuModel, String>, SortModel<PackageSkuModel>, IAssetsModel<PackageSkuModel, String> {

    @Schema(title = "已购名称")
    private String name;
    @Schema(title = "排序")
    private Integer sort;
    /**
     * 行业id
     * 值为"gjtk"时表示考试为高教题库
     */
    @Schema(title = "行业id 值为gjtk时表示考试为高教题库")
    private String industryId;
    @Schema(title = "考试id")
    private String examId;
    @Schema(title = "考试id")
    private String packageId;
    @Schema(title = "原价/分")
    private Long price;
    @Schema(title = "折扣价/分")
    private Long discountPrice;
    @Schema(title = "代理价/分")
    private Long agentPrice;
    @Schema(title = "天猫价/分")
    private Long tmPrice;
    @Schema(title = "售卖数量")
    private Integer sellCount;

    @Schema(title = "skuAttrIds")
    @TableField(typeHandler = JacksonTypeHandler.class)
    private List<String> skuAttrIds;
    @Schema(title = "科目集合")
    @TableField(typeHandler = JacksonTypeHandler.class)
    private List<Long> categoryIds;
    @Schema(title = "产品集合")
    @TableField(typeHandler = JacksonTypeHandler.class)
    private List<String> productIds;

    private String remark;
    @Schema(title = "是否上下架")
    private Boolean enable;

    @TableField(exist = false)
    @Schema(title = "行业名")
    private String industryName;
    @TableField(exist = false)
    @Schema(title = "考试名")
    private String examName;
    @TableField(exist = false)
    private String packageName;
    @TableField(exist = false)
    private List<String> categoryNameList;
    @TableField(exist = false)
    @Schema(title = "科目集合")
    private List<CategoryModel> categoryList;
    @TableField(exist = false)
    private List<String> skuAttrNameList;
    @TableField(exist = false)
    private String examType;
    @TableField(exist = false)
    @Schema(title = "有效期开始时间")
    private LocalDateTime startTime;
    @TableField(exist = false)
    @Schema(title = "有效期结束时间")
    private LocalDateTime endTime;
    @TableField(exist = false)
    @Schema(title = "资产是否有效")
    private AssetsStatus efficient;
    @TableField(exist = false)
    @Schema(title = "栏目类型")
    private List<ColumnType> columnType;
    public void setCategoryIds(List<?> categoryIds) {
        if (null != categoryIds) {
            this.categoryIds = categoryIds.stream().map(v -> {
                if (v instanceof Long l) return l;
                if (v instanceof Integer i) return i.longValue();
                if (v instanceof String s) return Long.valueOf(s);
                return 0L;
            }).toList();
        } else {
            this.categoryIds = null;
        }

    }
}
